<?php
/**
 * Created by PhpStorm.
 * 下载图片
 * User: ywf
 * Date: 2014/12/23
 * Time: 11:03
 */
    $msg='';
    $url = (isset($_REQUEST['img_url'])&&!empty($_REQUEST['img_url']))?$_REQUEST['img_url']:'';
    $num= isset($_REQUEST['img_num'])&&!empty($_REQUEST['img_num'])?$_REQUEST['img_num']:'1';
    if($url&&$num){
        if(!is_file('pic/'.$num.'.jpg')){
            $name = file_get_contents($url);
            if (file_put_contents('pic/'.$num.'.jpg', $name)) {
                $msg='保存成功';
            } else {
                $msg='保存失败';
            }
            $num++;
        }else{
            $msg='索引已存在';
        }
    }
?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>下载图片</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        </head>
    <body>
<form method="post" >
    图片地址：<input type="text" name="img_url" value="" size="30"><br>
    图片索引<input type="text" name="img_num" value="<?=$num?>"><br>
    <input type="submit" value="提交">
</form>
    <div ><?=$msg?></div>
    </body>
</html>